#include "Logger.h"

Logger::Logger(void)
{
}

Logger::~Logger(void)
{
}

void Logger::log(char *text)
{
    Logger::log(string(text));
}

void Logger::log(string text)
{
	Logger::createLogs();

	//Build output log
    char dateStr [9];
    char timeStr [9];
    _strdate( dateStr);
    _strtime( timeStr );

	string output("[" + string(dateStr) + " " + timeStr + "]: " + text);

	//Write log to console
	cout << output << endl;

	//Write log to logs/log.txt
	ofstream outputFile;
	outputFile.open("logs/log.txt", ios::out | ios::binary | ios::app);
    if (outputFile.fail() == 1)
    {
        outputFile.close();
        return;
    }   
	outputFile << output.c_str() << endl;
	outputFile.close();
}

void Logger::createLogs() 
{
	DIR *dir;

	dir = opendir("logs");
	if(dir == NULL) {
		mkdir("logs");
	}
	closedir(dir);
}